package com.example.dell.ssm.UI;

import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;

import com.example.dell.ssm.R;
import com.example.dell.ssm.adapter.LvAdapter;
import com.example.dell.ssm.adapter.RvAdapter;
import com.example.dell.ssm.contract.MainContract;
import com.example.dell.ssm.model.MainModel;
import com.example.dell.ssm.model.bean.ResponseBean;
import com.example.dell.ssm.model.bean.User;
import com.example.dell.ssm.presenter.MainPresenter;
import com.example.dell.ssm.view.RefreshLayout;
import com.google.gson.Gson;
import com.jaydenxiao.common.base.BaseActivity;
import com.jaydenxiao.common.commonutils.LogUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

public class MainActivity extends BaseActivity<MainPresenter, MainModel> implements MainContract.View {

    @Bind(R.id.main_rl)
    RefreshLayout mainRl;
//    @Bind(R.id.main_rv)
//    RecyclerView mainRv;
    @Bind(R.id.btn)
    Button btn;
    @Bind(R.id.btn2)
    Button btn2;
    @Bind(R.id.sv)
    ScrollView sv;
    private int i;
    private List<String> datas;
    private LvAdapter adapter;
    private RvAdapter rvAdapter;
    private int clickTime;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main2;
    }

    @Override
    public void initPresenter() {
        mPresenter.setVM(this, mModel);

    }

    @Override
    public void initView() {
        datas = new ArrayList<>();
        datas.addAll(initDatas());
//        rvAdapter = new RvAdapter(this, datas);
//        mainRv.setAdapter(rvAdapter);
//        mainRv.setLayoutManager(new LinearLayoutManager(this));
        mainRl.setLister(new RefreshLayout.PullToRefreshLister() {
            @Override
            public void onRefresh() {
                LogUtils.loge("----------------------");
                mPresenter.getRegister("sss", "ssssssssssssss");
            }
        });
    }

    @Override
    public void showLoading(String title) {

    }

    @Override
    public void stopLoading() {

    }

    @Override
    public void showErrorTip(String msg) {

    }

    @Override
    public void returnRegister(ResponseBean<User> userResponseBean) {
        LogUtils.loge(new Gson().toJson(userResponseBean));
//        mainRl.stopRefresh();
//        datas.addAll(initDatas());
//        rvAdapter.notifyDataSetChanged();
    }

    private List<String> initDatas() {
        List<String> datas = new ArrayList<>();
        i++;
        for (int j = 0; j < 5; j++) {
            datas.add("第 " + i + " 次加载,第  " + j + "条数据");
        }
        return datas;
    }


    @OnClick({R.id.btn, R.id.btn2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn:
                mainRl.startRefresh();
                break;
            case R.id.btn2:
                mainRl.stopRefresh();
                break;
        }
    }

}
